package com.ziroom.crm.mq.rabbit.spring.wrapper;

import com.ziroom.crm.mq.core.MqType;
import com.ziroom.crm.mq.core.processor.QueueWrapper;

import java.util.Optional;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author WeiShaoying
 * @version 1.0
 * @date Created in 2020年09月02日 11:38
 * @since 1.0
 */
public class RabbitSendQueueWrapper extends QueueWrapper {

    /**
     * 交换机
     */
    private final String exchange;

    /**
     * 路由键
     */
    private final String routingKey;


    public RabbitSendQueueWrapper(MqType mqType, String exchange, String routingKey) {
        super(resolveName(mqType, exchange, routingKey), mqType);
        this.exchange = exchange;
        this.routingKey = routingKey;
    }

    public String getExchange() {
        return exchange;
    }

    public String getRoutingKey() {
        return routingKey;
    }

    private static String resolveName(MqType mqType, String exchange, String routingKey) {
        StringBuilder builder = new StringBuilder();
        builder.append(mqType.name());
        Optional.ofNullable(exchange).ifPresent(builder::append);
        Optional.ofNullable(routingKey).ifPresent(builder::append);
        return builder.toString();
    }
}

